package com.mxw.rulesengine.controller;

import com.mxw.commons.restful.Result;
import com.mxw.rulesengine.mapper.domain.Person;
import com.mxw.rulesengine.mapper.domain.TtFactoringRiskParam;
import com.mxw.rulesengine.service.RuleEngineService;
import com.mxw.rulesengine.utils.RulesEngineUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/** @Description TODO @Author RingKo @Date 2022/8/3 18:48 @Version 1.0 */
@RestController
@RequestMapping("rule")
public class PersonRuleController {
  @Autowired private RuleEngineService ruleEngineService;

  @PostMapping("test")
  public void fireAllRules4One(@RequestBody Person person) {
    RulesEngineUtil.execute(person);
  }

  @GetMapping("reload")
  public void reloadAll() {
    ruleEngineService.reloadAll();
  }

  @GetMapping("reload/{id}")
  public void reloadAll(@PathVariable("id") Integer id) {
    ruleEngineService.reloadById(id);
  }

  @PostMapping("factoring")
  public Result<TtFactoringRiskParam> fireFactoring(@RequestBody TtFactoringRiskParam ttFactoringRiskParam) {
    RulesEngineUtil.execute(ttFactoringRiskParam);
    return Result.respond(ttFactoringRiskParam);
  }
}
